﻿using SmartMeterParamFrame.Model;
using System.Collections.ObjectModel;

namespace SchemeManager.Models
{
    /// <summary>
    /// 对原始方案进行扩展
    /// 扩展点：
    /// 增加对方案项目的分组
    /// </summary>
    public class Scheme : FACollection
    {
        /// <summary>
        /// 基本参数
        /// </summary>
        public ObservableCollection<FAinfo> BasicPara { get; set; }

        /// <summary>
        /// 一类参数
        /// </summary>
        public ObservableCollection<FAinfo> FirstPara { get; set; }

        /// <summary>
        /// 二类参数
        /// </summary>
        public ObservableCollection<FAinfo> SecondPara { get; set; }

        /// <summary>
        /// 费控参数
        /// </summary>
        public ObservableCollection<FAinfo> ConstPara { get; set; }

        /// <summary>
        /// 密钥参数
        /// </summary>
        public ObservableCollection<FAinfo> CryptKeyPara { get; set; }

        public Scheme()
            : base()
        { }

        public Scheme(string path, SmartMeterParamFrame.Interface.ICrypt crypt = null)
            : base(path, crypt)
        { }

        /// <summary>
        /// 进行分组
        /// </summary>
        public void DoGroyp()
        {
            BasicPara = new ObservableCollection<FAinfo>();
            FirstPara = new ObservableCollection<FAinfo>();
            SecondPara = new ObservableCollection<FAinfo>();
            ConstPara = new ObservableCollection<FAinfo>();
            CryptKeyPara = new ObservableCollection<FAinfo>();
            for (int i = 0; i < Count; i++)
            {
                FAinfo curItem = this[i];
                switch (curItem.PrjType)
                {
                    case SmartMeterParamFrame.EnumFAType.其他操作:
                        {
                            BasicPara.Add(curItem);
                        }
                        break;
                    case SmartMeterParamFrame.EnumFAType.一类参数:
                        {
                            FirstPara.Add(curItem);
                        }
                        break;
                    case SmartMeterParamFrame.EnumFAType.二类参数:
                        {
                            SecondPara.Add(curItem);
                        }
                        break;
                    case SmartMeterParamFrame.EnumFAType.费控功能:
                        {
                            ConstPara.Add(curItem);
                        }
                        break;
                    case SmartMeterParamFrame.EnumFAType.密钥下装:
                        {
                            CryptKeyPara.Add(curItem);
                        }
                        break;

                }


            }
        }

        /// <summary>
        /// 把所有项目聚合到整体中
        /// </summary>
        public void Join()
        {
            Clear();
            //基本参数
            foreach (FAinfo item in BasicPara)
            {
                Add(item);
            }

            //一类参数
            foreach (FAinfo item in FirstPara)
            {
                Add(item);
            }
            //二类参数
            foreach (FAinfo item in SecondPara)
            {
                Add(item);
            }
            //费控功能
            foreach (FAinfo item in ConstPara)
            {
                Add(item);
            }
            //密钥下装
            foreach (FAinfo item in CryptKeyPara)
            {
                Add(item);
            }
        }

    }
}
